import {request} from '../request'
import qs from 'qs';

//条件查询管理员
export function getAdminByKey(search){
  return request({
    url:'/api/admin/getAdminByKey',
    method:'post',
    data: search
  })
}

//获取所有管理员的信息
export function getAllAdministrators(){
  return request({
    url:'/api/admin/getAllAdmin',
    method:'get',
  });
}

//重置密码
export function resetAdPassword(id){
  return request({
    url:'/api/admin/resetAdPassword',
    method:'get',
    params: {
      id
    }
  })
}

//编辑管理员
export function updateAdmin(admin){
  return request({
    url:'/api/admin/updateAdmin',
    method: 'post',
    data:{
      ad_id: admin.ad_id,
      ad_uname:admin.ad_uname,
      ad_name: admin.ad_name,
      ad_pw: admin.ad_pw,
      ad_sex: admin.ad_sex,
      ad_phone: admin.ad_phone,
      ad_email: admin.ad_email,
      ad_status: admin.ad_status,
      ad_rank: admin.ad_rank
    }
  })
}

//删除管理员
export function deleteAdmin(id){
  return request({
    url:'/api/admin/deleteAdmin',
    method: 'post',
    data: qs.stringify({id}),
    headers: {'Content-Type': 'application/x-www-form-urlencoded'}
  })
}

//添加管理员
export function addAdmin(admin){
  return request({
    url:'/api/admin/addAdmin',
    method: 'post',
    data:{
      ad_uname:admin.ad_uname,
      ad_name: admin.ad_name,
      ad_pw: admin.ad_pw,
      ad_sex: admin.ad_sex,
      ad_phone: admin.ad_phone,
      ad_email: admin.ad_email,
      ad_status: admin.ad_status,
      ad_rank: admin.ad_rank
    }
  })
}

//  冻结、解冻管理员账号
export function toggleAdStatus(id){
  return request({
    url:'/api/admin/updateAdminStatus',
    method: 'post',
    data: qs.stringify({id:id}),
    headers: {'Content-Type':'application/x-www-form-urlencoded'}
  })
}

//修改管理员密码
export function updatePassword(admin){
  return request({
    url:'/api/admin/updatePassword',
    method:'post',
    data:{
      id: admin.id,
      oldPassword: admin.oldPassword,
      newPassword: admin.newPassword
    }
  })
}
